home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1377 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. Path: engnews2.Eng.Sun.COM!usenet
  2. From: nitin@more.eng.sun.com (Nitin More [CONTRACTOR])
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: locking
  5. Date: 10 Jan 1996 18:30:13 GMT
  6. Organization: SunSoft
  7. Message-ID: <NITIN.96Jan10103013@more.eng.sun.com>
  8. References: <4d0j6r$1ri@daphne.ecmwf.int>
  9.     <30F3E9C3.15FB7483@intellektik.informatik.th-darmstadt.de>
  10. NNTP-Posting-Host: more.eng.sun.com
  11. In-reply-to: Enno Sandner's message of Wed, 10 Jan 1996 17:30:59 +0100
  12.  
  13. In article <30F3E9C3.15FB7483@intellektik.informatik.th-darmstadt.de> Enno Sandner <enno@intellektik.informatik.th-darmstadt.de> writes:
  14.  
  15. > From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
  16.  
  17. [deleted]
  18.  
  19. > > 
  20. > > This seems to work, but the LockObject is only destroyed at the
  21. > > end of the block, locking my object for too long.
  22. > > 
  23. > > main()
  24. > > {
  25. > > 
  26. > >         SharedObject<foo> fooH("lock");
  27. > > 
  28. > >         ... the lock is not set
  29. > > 
  30. > >         fooH->bar();
  31. > > 
  32. > >         .. the lock is set until the end.
  33. > > }
  34. > > 
  35. > > Anyone got an idea ?
  36. > > 
  37. > I would say the temporary object should be destroyed directly after
  38. > the invocation of 'bar'.
  39. > As a workarround you can put the member-function call in brackets, e.g.
  40. >             { foo->bar(); }
  41. >     Enno
  42.  
  43. You need to put the declaration of fooH also in the block as follows:
  44.  
  45.     {
  46.         SharedObject<foo> fooH("lock");
  47.         fooH->bar();
  48.     .. the lock is set until the end **OF THE BLOCK**
  49.     }
  50.     .. fooH is destructed at the end of the block releasing the lock.
  51.  
  52. -Nitin
  53.  
  54.  
  55. -- 
  56. ----------------------------------------------------------------------
  57. Nitin More                                                         
  58. SunSoft, Bldg 16  Off: (415) 786 7109                                 
  59. Menlo Park, CA    Fax: (415) 786 7957   e-mail: nitin@more.eng.sun.com
  60. ----------------------------------------------------------------------
  61.